<?php defined('SYSPATH') or die('No direct script access.');

/**
 *
 * @author pahhan
 */
class Task_Parser_Info extends Minion_Task
{
    protected $_options = array(
        'id' => NULL,
    );

    public function build_validation(Validation $validation)
    {
        return parent::build_validation($validation)
            ->rule('id', 'not_empty') // Require this param
            ->rule('id', 'numeric'); // This param should be numeric
    }

    protected function _execute(array $params)
    {
        $id = $params['id'];
        $pi = ORM::factory('ParseInfo', $id);
        if( !$pi->id ) throw new Exception(sprintf('ParseInfo with id=%s not found', $id));

        echo PHP_EOL;
        printf('Parser #%d'.PHP_EOL, $id);
        printf("Site #%d:\t%s\n", $pi->site->id, $pi->site->title);
        printf("Status:\t\t%s\n", $pi->is_active? 'active' : 'not active');
        printf("Url:\t\t%s\n", $pi->url);
        printf("Last msg id:\t%d\n", $pi->last_message_id);
        printf("Last ext id:\t%s\n", $pi->last_external_id);
        printf("Last update:\t%s\n", $pi->last_update);
        printf("Messages:\t%d\n", $pi->getMessagesCount());
        printf("Class key:\t%s\n", $pi->class_key);
        echo PHP_EOL;


    }

}

